* join is_fatal lines in prep for transformation.
1,$g/is_fatal.*[^;]$/j
* replace is_fatal with if() fatal().
this allows better static analysis.
sed -i '1,$s/^\( *\)is_fatal *( *\(.*\), *MYNAME\([^;]*\);$/\1if (\2) {\n\1 fatal(MYNAME\3;\n\1}/' $file
sed -i '1,$s/^\( *\)is_fatal *( *\(.*\), *"\([^;]*\);$/\1if (\2) {\n\1 fatal("\3;\n\1}/' $file
* manual delete extra parenthesis.
[[noreturn]] void fatal(QDebug& msginstance);
[[noreturn]] void fatal(const char*, ...) PRINTFLIKE(1, 2);
-void is_fatal(int condition, const char*, ...) PRINTFLIKE(2, 3);
void warning(const char*, ...) PRINTFLIKE(1, 2);
void printposn(double c, int is_lat);
gbfrewind(ftmp);
uint32_t ident = gbfgetuint32(ftmp);
- is_fatal(ident != 0x66697845, MYNAME ": Invalid EXIF header magic.");
- is_fatal(gbfgetint16(ftmp) != 0, MYNAME ": Error in EXIF header.");
+ if (ident != 0x66697845) {
+ fatal(MYNAME ": Invalid EXIF header magic.");
+ }
+ if (gbfgetint16(ftmp) != 0) {
+ fatal(MYNAME ": Error in EXIF header.");
+ }
uint16_t endianness = gbfgetint16(ftmp);
if (global_opts.debug_level >= 3) {
exif_read()
{
uint16_t soi = gbfgetuint16(fin_);
- is_fatal(soi != 0xFFD8, MYNAME ": Unknown image file."); /* only jpeg for now */
+ /* only jpeg for now */
+ if (soi != 0xFFD8) {
+ fatal(MYNAME ": Unknown image file.");
+ }
exif_app_ = exif_load_apps();
- is_fatal(exif_app_ == nullptr, MYNAME ": No EXIF header in source file \"%s\".", fin_->name);
+ if (exif_app_ == nullptr) {
+ fatal(MYNAME ": No EXIF header in source file \"%s\".", fin_->name);
+ }
exif_examine_app(exif_app_);
Waypoint* wpt = exif_waypt_from_exif_app(exif_app_);
exif_apps = new QList<ExifApp*>;
fin_ = gbfopen_be(fname, "rb", MYNAME);
- is_fatal(fin_->is_pipe, MYNAME ": Sorry, this format cannot be used with pipes!");
+ if (fin_->is_pipe) {
+ fatal(MYNAME ": Sorry, this format cannot be used with pipes!");
+ }
uint16_t soi = gbfgetuint16(fin_);
- is_fatal(soi != 0xFFD8, MYNAME ": Unknown image file.");
+ if (soi != 0xFFD8) {
+ fatal(MYNAME ": Unknown image file.");
+ }
exif_app_ = exif_load_apps();
- is_fatal(exif_app_ == nullptr, MYNAME ": No EXIF header found in source file \"%s\".", fin_->name);
+ if (exif_app_ == nullptr) {
+ fatal(MYNAME ": No EXIF header found in source file \"%s\".", fin_->name);
+ }
exif_examine_app(exif_app_);
gbfclose(fin_);
char northSouth, eastWest, velocityMark, ttRec[TTRECORDSIZE], tempBuf[20];
int year, mon, mday, hour, min, sec, latitudeDeg, latitudeMin, longitudeDeg, longitudeMin, velocity;
- is_fatal((track == nullptr), MYNAME "Track setup error");
+ if (track == nullptr) {
+ fatal(MYNAME "Track setup error");
+ }
for (;;) {
if ((gbfread((void*)ttRec, 1, 2, fin) != 2)
|| (memcmp(ttRec,"TT",2))) {
// data length
fit_data.len = gbfgetuint32(fin);
// File signature
- is_fatal(gbfread(sig, 4, 1, fin) != 1,
- MYNAME ": Unexpected end of file\n");
+ if (gbfread(sig, 4, 1, fin) != 1) {
+ fatal(MYNAME ": Unexpected end of file\n");
+ }
if (sig[0] != '.' || sig[1] != 'F' || sig[2] != 'I' || sig[3] != 'T') {
fatal(MYNAME ": .FIT signature missing\n");
}
char first = gbfgetc(fin);
if (first == 0) {
- is_fatal((gbfgetc(fin) != 0),
- MYNAME ": Error reading field '%s'!", field);
+ if (gbfgetc(fin) != 0) {
+ fatal(MYNAME ": Error reading field '%s'!", field);
+ }
lc_string res1 = gpi_read_lc_string();
if ((res1.strlen + 4) < l0) { // dual language?
lc_string res2 = gpi_read_lc_string();
- is_fatal((res1.strlen + 4 + res2.strlen + 4 != l0),
- MYNAME ": Error out of sync (wrong size %d/%d/%d) on field '%s'!", l0, res1.strlen, res2.strlen, field);
+ if (res1.strlen + 4 + res2.strlen + 4 != l0) {
+ fatal(MYNAME ": Error out of sync (wrong size %d/%d/%d) on field '%s'!", l0, res1.strlen, res2.strlen, field);
+ }
if (opt_lang && (opt_lang == res1.lc)) {
string = res1.str;
} else if (opt_lang && (opt_lang == res2.lc)) {
fatal(MYNAME ": Must select language code, %s and %s found.\n", res1.lc.constData(), res2.lc.constData());
}
} else { // normal case, single language
- is_fatal((res1.strlen + 4 != l0),
- MYNAME ": Error out of sync (wrong size %d/%d) on field '%s'!", l0, res1.strlen, field);
+ if (res1.strlen + 4 != l0) {
+ fatal(MYNAME ": Error out of sync (wrong size %d/%d) on field '%s'!", l0, res1.strlen, field);
+ }
string = res1.str;
}
} else {
unsigned char* ptr;
gbfile* f = gbfopen_le(fname, "rb", MYNAME);
- is_fatal(gbfgetint16(f) != 0x4d42, MYNAME ": No BMP image.");
+ if (gbfgetint16(f) != 0x4d42) {
+ fatal(MYNAME ": No BMP image.");
+ }
/* read a standard bmp file header */
src_h.size = gbfgetint32(f);
init_date_and_time_format();
if (opt_precision) {
precision = atoi(opt_precision);
- is_fatal(precision < 0, MYNAME ": Invalid precision (%s)!", opt_precision);
+ if (precision < 0) {
+ fatal(MYNAME ": Invalid precision (%s)!", opt_precision);
+ }
}
datum_str = get_option_val(opt_datum, nullptr);
char* cerr = strptime(cin, date_time_format, &tm);
if (cerr == nullptr) {
cerr = strptime(cin, "%m/%d/%Y %I:%M:%S %p", &tm);
- is_fatal(cerr == nullptr, MYNAME ": Invalid date or/and time \"%s\" at line %d!", qPrintable(tstr), current_line);
+ if (cerr == nullptr) {
+ fatal(MYNAME ": Invalid date or/and time \"%s\" at line %d!", qPrintable(tstr), current_line);
+ }
}
// printf(MYNAME "_parse_date_and_time: %02d.%02d.%04d, %02d:%02d:%02d\n",
static void
bind_fields(const header_type ht)
{
- is_fatal((grid_index < 0) || (datum_index < 0), MYNAME ": Incomplete or invalid file header!");
+ if ((grid_index < 0) || (datum_index < 0)) {
+ fatal(MYNAME ": Incomplete or invalid file header!");
+ }
if (header_ct[unknown_header] <= 0) {
return;
int field_no = header_fields[rtept_header][column];
switch (field_no) {
case 1:
- is_fatal((str.isEmpty()), MYNAME ": Route waypoint without name at line %d!\n", current_line);
+ if (str.isEmpty()) {
+ fatal(MYNAME ": Route waypoint without name at line %d!\n", current_line);
+ }
wpt = find_waypt_by_name(str);
- is_fatal((wpt == nullptr), MYNAME ": Route waypoint \"%s\" not in waypoint list (line %d)!\n", qPrintable(str), current_line);
+ if (wpt == nullptr) {
+ fatal(MYNAME ": Route waypoint \"%s\" not in waypoint list (line %d)!\n", qPrintable(str), current_line);
+ }
wpt = new Waypoint(*wpt);
break;
}
/* we are at the end of the file */
if (global_opts.debug_level > 0) {
/* now gzeof() should return 1 */
- is_fatal(!gzeof(self->handle.gz), "zlib gzeof error!\n");
+ if (!gzeof(self->handle.gz)) {
+ fatal("zlib gzeof error!\n");
+ }
}
res = 1;
}
{
char buf[4];
- is_fatal((gbfread(&buf, 1, sizeof(buf), file) != sizeof(buf)),
- "%s: Unexpected end of file (%s)!\n", file->module, file->name);
+ if (gbfread(&buf, 1, sizeof(buf), file) != sizeof(buf)) {
+ fatal("%s: Unexpected end of file (%s)!\n", file->module, file->name);
+ }
if (file->big_endian) {
return be_read32(buf);
{
char buf[2];
- is_fatal((gbfread(&buf, 1, sizeof(buf), file) != sizeof(buf)),
- "%s: Unexpected end of file (%s)!\n", file->module, file->name);
+ if (gbfread(&buf, 1, sizeof(buf), file) != sizeof(buf)) {
+ fatal("%s: Unexpected end of file (%s)!\n", file->module, file->name);
+ }
if (file->big_endian) {
return be_read16(buf);
{
char buf[8];
- is_fatal((gbfread(&buf, 1, sizeof(buf), file) != sizeof(buf)),
- "%s: Unexpected end of file (%s)!\n", file->module, file->name);
+ if (gbfread(&buf, 1, sizeof(buf), file) != sizeof(buf)) {
+ fatal("%s: Unexpected end of file (%s)!\n", file->module, file->name);
+ }
return endian_read_double(buf, ! file->big_endian);
}
{
char buf[4];
- is_fatal((gbfread(&buf, 1, sizeof(buf), file) != sizeof(buf)),
- "%s: Unexpected end of file (%s)!\n", file->module, file->name);
+ if (gbfread(&buf, 1, sizeof(buf), file) != sizeof(buf)) {
+ fatal("%s: Unexpected end of file (%s)!\n", file->module, file->name);
+ }
return endian_read_float(buf, ! file->big_endian);
}
}
QByteArray ba;
ba.resize(len);
- is_fatal((gbfread(ba.data(), 1, len, file) != (gbsize_t) len),
- "%s: Unexpected end of file (%s)!\n", file->module, file->name);
+ if (gbfread(ba.data(), 1, len, file) != (gbsize_t) len) {
+ fatal("%s: Unexpected end of file (%s)!\n", file->module, file->name);
+ }
return QString(ba);
}
The following message "local buffer overflow detected..." could be
misinterpreted.
*/
- is_fatal(strcmp(buf, "MsRcf") != 0, MYNAME ": Invalid file \"%s\"!", fin->name);
+ if (strcmp(buf, "MsRcf") != 0) {
+ fatal(MYNAME ": Invalid file \"%s\"!", fin->name);
+ }
int reclen = FREAD_i32;
Q_UNUSED(reclen);
QByteArray drec = FREAD_STR();
- is_fatal(drec.at(0) != 'D', MYNAME ": Invalid file \"%s\"!", fin->name);
+ if (drec.at(0) != 'D') {
+ fatal(MYNAME ": Invalid file \"%s\"!", fin->name);
+ }
gdb_ver = drec.at(1) - 'k' + 1;
- is_fatal((gdb_ver < GDB_VER_MIN) || (gdb_ver > GDB_VER_MAX),
- MYNAME ": Unknown or/and unsupported GDB version (%d.0)!", gdb_ver);
+ if ((gdb_ver < GDB_VER_MIN) || (gdb_ver > GDB_VER_MAX)) {
+ fatal(MYNAME ": Unknown or/and unsupported GDB version (%d.0)!", gdb_ver);
+ }
if (global_opts.verbose_status > 0) {
printf(MYNAME ": Reading Garmin GPS Database version %d.0\n", gdb_ver);
}
reclen = FREAD_i32;
- is_fatal((reclen + 1 > int(sizeof(buf))),
- MYNAME ": Invalid record length\n");
+ if (reclen + 1 > int(sizeof(buf))) {
+ fatal(MYNAME ": Invalid record length\n");
+ }
(void) FREAD(buf, reclen + 1);
if (global_opts.verbose_status > 0) {
const char* name = buf+2;
}
QByteArray applicationField = FREAD_STR();
- is_fatal(!((applicationField == "MapSource") || (applicationField == "BaseCamp")), MYNAME ": Not a recognized signature in header");
+ if (!((applicationField == "MapSource") || (applicationField == "BaseCamp"))) {
+ fatal(MYNAME ": Not a recognized signature in header");
+ }
}
/*-----------------------------------------------------------------------------*/
}
int delta = len - gbftell(ftmp);
- is_fatal(delta > 1000000, "Internal consistency error. Delta too big");
+ if (delta > 1000000) {
+ fatal("Internal consistency error. Delta too big");
+ }
// Avoid finite loop on bogus beta files from '06.
// THe 100000 is totally pulled from my hat.
gdb_ver = (gdb_opt_ver && *gdb_opt_ver) ? atoi(gdb_opt_ver) : 0;
if (gdb_category) {
- is_fatal((gdb_category < 1) || (gdb_category > 16),
- MYNAME ": cat must be between 1 and 16!");
+ if ((gdb_category < 1) || (gdb_category > 16)) {
+ fatal(MYNAME ": cat must be between 1 and 16!");
+ }
gdb_category = 1 << (gdb_category - 1);
}
result=serial_recv_byte();
} else {
result = gbfgetc(in_file);
- is_fatal((result < 0), MYNAME ": read error");
+ if (result < 0) {
+ fatal(MYNAME ": read error");
+ }
}
// Check if byte should be dumped also into a file
if (dumpfile) {
} else {
// read from dump-file instead of serial
in_file = gbfopen(fname, "rb", MYNAME);
- is_fatal(!in_file, "Could not open dumpfile for input: %s", qPrintable(fname));
+ if (!in_file) {
+ fatal("Could not open dumpfile for input: %s", qPrintable(fname));
+ }
}
if (opt_timezone) {
QString rte_name;
if (explorist) {
char* ca = rtemsg + n;
- is_fatal(*ca++ != ',', MYNAME ": Incorrectly formatted route line '%s'", rtemsg);
+ if (*ca++ != ',') {
+ fatal(MYNAME ": Incorrectly formatted route line '%s'", rtemsg);
+ }
char* ce = strchr(ca, ',');
- is_fatal(ce == nullptr, MYNAME ": Incorrectly formatted route line '%s'", rtemsg);
+ if (ce == nullptr) {
+ fatal(MYNAME ": Incorrectly formatted route line '%s'", rtemsg);
+ }
if (ca == ce) {
rte_name = "Route";
int end_flag = gbfgetint32(fin);
while (!end_flag) {
int length = gbfgetint32(fin);
- is_fatal((length < 1) || (length > 1600), MYNAME ": get bad buffer length");
+ if ((length < 1) || (length > 1600)) {
+ fatal(MYNAME ": get bad buffer length");
+ }
- is_fatal((length % 8 != 0), MYNAME ": bad buffer size");
+ if (length % 8 != 0) {
+ fatal(MYNAME ": bad buffer size");
+ }
gbfseek(fin, 16, SEEK_CUR);
const int amount = length/8;
objid = mmo_object_id++;
uint16_t version = gbfgetuint16(fin);
- is_fatal(version != mmo_version, MYNAME ": Invalid version identifier!\n");
+ if (version != mmo_version) {
+ fatal(MYNAME ": Invalid version identifier!\n");
+ }
int len = gbfgetint16(fin);
static void
enum_route_hdr_cb(const route_head* rte)
{
- is_fatal(rte->rte_waypt_ct() > 50,
- MYNAME ": Routes with more than 50 points are not supported by Raymarine!");
+ if (rte->rte_waypt_ct() > 50) {
+ fatal(MYNAME ": Routes with more than 50 points are not supported by Raymarine!");
+ }
}
static short_handle
switch (*c) {
case '%':
fmt = *++c;
- is_fatal(fmt == '\0', "No character after %% in subrip format");
+ if (fmt == '\0') {
+ fatal("No character after %% in subrip format");
+ }
switch (fmt) {
case 's':
case '\\':
fmt = *++c;
- is_fatal(fmt == '\0', "No character after \\ in subrip format");
+ if (fmt == '\0') {
+ fatal("No character after \\ in subrip format");
+ }
switch (fmt) {
case 'n':
gbfprintf(fout, "\n");
}
}
int ct = sscanf(str, "%d%1[.://]%d%1[.://]%d%lf", &hour, sep, &min, sep, &sec, &us);
- is_fatal(ct < 5, MYNAME ": Could not parse time string (%s).\n", str);
+ if (ct < 5) {
+ fatal(MYNAME ": Could not parse time string (%s).\n", str);
+ }
if (ct == 6) {
*usec = lround((us * 1000000));
if (*usec > 999999) {
printf("%f%c ", fabs(c), d);
}
-void
-is_fatal(const int condition, const char* fmt, ...)
-{
- va_list args;
- char buff[128];
-
- if (condition == 0) {
- return;
- }
-
- va_start(args, fmt);
- vsnprintf(buff, sizeof(buff), fmt, args);
- va_end(args);
-
- fatal("%s\n", buff);
-}
-
/*
* Read 4 bytes in big-endian. Return as "int" in native endianness.
*/
okay = 0;
}
- is_fatal(okay == 0, "Invalid character \"%c\" in date format!", *cin);
+ if (okay == 0) {
+ fatal("Invalid character \"%c\" in date format!", *cin);
+ }
}
return result;
}
okay = 0;
}
- is_fatal(okay == 0, "Invalid character \"%c\" in time format!", *cin);
+ if (okay == 0) {
+ fatal("Invalid character \"%c\" in time format!", *cin);
+ }
}
return result;
}
c = "0";
} else {
int test;
- is_fatal(1 != sscanf(c, "%d", &test),
- "%s: Invalid parameter value %s for option %s", qPrintable(module), val, arg->argstring);
+ if (1 != sscanf(c, "%d", &test)) {
+ fatal("%s: Invalid parameter value %s for option %s", qPrintable(module), val, arg->argstring);
+ }
}
break;
case ARGTYPE_FLOAT:
c = "0";
} else {
double test;
- is_fatal(1 != sscanf(c, "%lf", &test),
- "%s: Invalid parameter value %s for option %s", qPrintable(module), val, arg->argstring);
+ if (1 != sscanf(c, "%lf", &test)) {
+ fatal("%s: Invalid parameter value %s for option %s", qPrintable(module), val, arg->argstring);
+ }
}
break;
case ARGTYPE_BOOL:
datum_name = "WGS 84";
}
xcsv_file->gps_datum_idx = GPS_Lookup_Datum_Index(datum_name);
- is_fatal(xcsv_file->gps_datum_idx < 0, MYNAME ": datum \"%s\" is not supported.", qPrintable(datum_name));
+ if (xcsv_file->gps_datum_idx < 0) {
+ fatal(MYNAME ": datum \"%s\" is not supported.", qPrintable(datum_name));
+ }
assert(gps_datum_wgs84 == GPS_Lookup_Datum_Index("WGS 84"));
}
datum_name = "WGS 84";
}
xcsv_file->gps_datum_idx = GPS_Lookup_Datum_Index(datum_name);
- is_fatal(xcsv_file->gps_datum_idx < 0, MYNAME ": datum \"%s\" is not supported.", qPrintable(datum_name));
+ if (xcsv_file->gps_datum_idx < 0) {
+ fatal(MYNAME ": datum \"%s\" is not supported.", qPrintable(datum_name));
+ }
assert(gps_datum_wgs84 == GPS_Lookup_Datum_Index("WGS 84"));
}